<!DOCTYPE html>
<html>

<head>
    <head/>
    <title>预约详情</title>
    <%- include('./_global/baseLibs') %>

        <style type="text/css">
            .yyxq-box .last-btn-box .btn-left {
                width: 48% !important;
                margin-left: 4%;
            }

            textarea {
                border: 1px solid #666;
                border-radius: 5px;
                text-indent: 8px;
            }
        </style>
</head>


<body>
    <section class="page-wrap yyxq-box yyxx-box">
        <!-- <header class="header-box grey fixed">
            <div class="header-content">
                <div class="left-tool">
                    <a class="back" href="javascript:void(0);">
                        <i class="iconfont icon-back"></i>
                    </a>
                </div>
                <div class="title">预约详情</div>
            </div>
        </header> -->
        <div class="first-box">
            <span class="first-text orderInfo" name="orderStatus"></span>
            <span class="orderInfo" name="orderInfo"></span>
        </div>
        <div class="second-box">
            <div class="yy-message">
                <span class="title-text">预约信息</span>
                <p>
                    <span class="text-left">就诊医院：</span>
                    <span class="orderInfo" name="hosName"></span>
                </p>
                <p>
                    <span class="text-left">就诊科室：</span>
                    <span class="orderInfo" name="depName"></span>
                </p>
                <p>
                    <span class="text-left">就诊医生：</span>
                    <span class="orderInfo" name="docName"></span>
                </p>
                <p>
                    <span class="text-left">就诊时间：</span>
                    <span class="orderInfo" name="jzsj"></span>
                </p>
                <!-- <p><span class="text-left">候诊地点：</span><span class="orderInfo" name="position"></span></p> -->
                <p>
                    <span class="text-left">门诊费用：</span>
                    <span class="orderInfo" name="mzType"></span>
                </p>
            </div>
            <!-- <a class="ck-map" href="javascript:void(0);">查看地图</a> -->
            <a class="fk-text orderInfo" name="">到院支付</a>
        </div>
        <div class="third-box">
            <div class="person-message">
                <span class="title-text">就诊人信息</span>
                <p>
                    <span class="text-left">就诊人：</span>
                    <span class="orderInfo" name="patientName"> </span>
                </p>
                <p>
                    <span class="text-left">身份证号：</span>
                    <span class="orderInfo" name="patientCardId"></span>
                </p>
                <p>
                    <span class="text-left">手机号：</span>
                    <span class="orderInfo" name="patientPhone"></span>
                </p>
            </div>
        </div>
        <div class="forth-box">
            <div class="remind-box">
                <span class="title-text">温馨提示</span>
                <span class="orderInfo" name="qxsj"></span>
                <span>在就诊前医生若停诊医院会短信通知</span>
                <span class="orderInfo" name="lxdh"></span>
            </div>
        </div>
        <div class="last-btn-box">
            <!-- <a class="btn-left" href="javascript:void(0);">再次预约</a>
        <a class="btn-right" href="javascript:void(0);">立即评价</a> -->
        </div>
    </section>

</body>
<script type="text/html" id="cgBtn">
    <!-- <a class="btn-single" id="topay" href="javascript:void(0);" >立即支付</a> -->
    <a class="btn-left reservationAgain" href="javascript:void(0);">再次预约</a>
    <!-- <a class="btn-right" href="javascript:void(0);" onclick="qxyy('#orderId#')">取消预约</a> -->
    <a class="btn-right qxyy" href="javascript:void(0);">取消预约</a>
</script>
<script type="text/html" id="qxBtn">
    <a class="btn-left reservationAgain" href="javascript:void(0);">再次预约</a>
</script>
<script type="text/html" id="jzBtn">
    <a class="btn-left reservationAgain" href="javascript:void(0);">再次预约</a>
    <a class="btn-right jzpj" href="javascript:void(0);">立即评价</a>
</script>
<script src="/static/lib/forweb.js"></script>
<script src="/quickJs/scripts/swiper/3.4.2/js/swiper.min.js"></script>
<!-- start支付引用。需传入支付成功后跳转的url.还有擦掉按钮之后的行为。需要调用toGetPay 传入获取订单相关信息的参数 -->


<!-- end -->
<script type="text/javascript">
    var requestRoot = "/gzd/yygh/";
    var hosOrgCode = $.QuickUrlUtils.getRequest("hosCode");
    var orderId = $.QuickUrlUtils.getRequest("orderId");
    var oneDepCode = $.QuickUrlUtils.getRequest("oneDepCode");



    /**取消预约*/
    function qxyy(data) {
        /**取消预约*/
        $.QuickAlert.alertConfirm({
            content: "<div style='margin:-38px 0px -25px 0px;'><div style='float:left;margin-top:30px;'>退号原因：</div><textarea  id=\"cancelReason\" rows='3' cols='20' border='1'></textarea></div>",
            title: "确认是否退号",
            callback: function (cancelReason) {
                // var data = StoreCache.getCache("yyInfo");    

            },
            yes: function (index) {

                if (StringUtils.isEmpty($("#cancelReason").val())) {
                    $.QuickAlert.alertNormal("请填写退号原因！", {
                        callback: function (indexAlert) {
                            layer.close(indexAlert);
                        }
                    });

                } else {
                    var cancelReason = $("#cancelReason").val();

                    var params = {
                        orderId: data.orderId,
                        hosOrgCode: data.hosCode,
                        cancelReason: cancelReason,

                    }
                    // $.QuickRemote.AjaxJson({
                    //     funcName: "/api" + requestRoot + "cancelReservation",
                    //     callback: function (result) {

                    //         $.QuickAlert.alertNormal("取消预约成功！", {
                    //             callback: function () {

                    //                 location.reload();

                    //             }
                    //         });
                    //     },
                    //     params: params
                    // });

                    $.ajax({
                        type: "POST", // 使用get方法访问后台
                        dataType: "json", // 返回json格式的数据
                        "headers": {
                            "Content-Type": "application/json",
                            "Cache-Control": "no-cache",
                        },
                        url: "/api/yyghAdapter/cancelReservation", // 要访问的后台地址
                        data: JSON.stringify(params),
                        success: function (result) {
                            if (result.code == "SUCCESS") {
                                $.QuickAlert.alertNormal("取消预约成功！", {
                                    callback: function () {
                                        var isReg = data["orderType"] == "1" ? (
                                            data.depName + " " + "专家门诊 " + " " +
                                            "(" + data.docName + "医生)") : (data
                                            .depName + " " + "普通门诊 ");

                                        var sendMsg = {
                                            phone : data.patientPhone,
                                            // phone: "18501614744",
                                            content: "【" + data.hosName + "】" +
                                                data.patientName + ",您预约的" +
                                                data.scheduleDate + ", " +
                                                "科室名称" + " " + isReg + " 就诊时间为" +
                                                data.startTime + " - " + data.endTime +
                                                " 的号源已取消，谢谢您的支持。祝您生活愉快!"
                                        };

                                        // 发送短信
                                        $.ajax({
                                            type: "POST", // 使用get方法访问后台
                                            dataType: "json", // 返回json格式的数据
                                            "headers": {
                                                "Content-Type": "application/json",
                                                "Cache-Control": "no-cache",
                                            },
                                            url: "/api/yyghAdapter/sendMsg", // 要访问的后台地址
                                            data: JSON.stringify(sendMsg),
                                            success: function (data) {
                                                if (data.code ==
                                                    "SUCCESS") {
                                                    // debugger;
                                                    location.reload();

                                                } else {
                                                    $.QuickAlert.alertFail({
                                                        content: data
                                                            .message
                                                    });
                                                }
                                            }
                                        });

                                        
                                    }
                                });



                            } else {
                                $.QuickAlert.alertFail({
                                    content: data.message
                                });
                            }
                        }
                    });

                }

            }


        });


        /*$.QuickAlert.alertConfirm({content: "确认是否退号?",title: "系统提示",callback: function(){
           
            var params = {
                orderId:result.orderId,
                hosOrgCode:result.hosCode,
                cancelReason:""
            }
            $.QuickRemote.AjaxJson({
                funcName:"/api"+requestRoot + "cancelReservation"
                ,callback:function(result){
                    $.QuickAlert.alertNormal("取消预约成功！",{callback: function(){
                        
                        location.reload();

                    }});
                },params:params
            });
        }});*/
    }

    var page_yyDetailWithoutPay = (function ($, page_yyDetailWithoutPay) {

        /**加载视图*/
        function initMapHandler(hosInfo) {
            /**查看地图*/
            $(".ck-map").on("click", function () {
                var str = hosInfo["hosLocation"];
                if (str) {
                    var strs = str.split(",");
                    var params = {
                        longitude: strs[0],
                        latitude: strs[1],
                        hosName: hosInfo["hosName"]
                    };
                    $.JkcsUtils.gotoMap(params);
                }
            });
        }
        /**加载数据*/
        function initData() {
            /**获取预约单编号*/
            /*YYGH_HYCGINFO*/

            // var oneDepCode = $.QuickUrlUtils.getRequest("oneDepCode");

            var params = {
                hosOrgCode: hosOrgCode,
                orderId: orderId,
                oneDepCode: oneDepCode

            }


            // $.QuickRemote.AjaxJson({
            //     funcName: "/api/yyghAdapter/getOrderDetail",
            //     callback: function (data) {
            //         /**获取预约信息*/

            //         StoreCache.setCache("YYGH_YYDETAILINFO", data);
            //         /**预约单信息赋值*/
            //         data = page_yyDetailWithoutPay.getOrderInfo(data);
            //         $("body").find(".orderInfo").each(function () {
            //             if ($(this).attr("name") == "orderStatus") {
            //                 $(this).text(page_yyDetailWithoutPay.getStatus(data.orderStatus));
            //             } else {
            //                 $(this).text(data[$(this).attr("name")]);
            //             }
            //         });

            //     },
            //     params: params
            // });
            $.ajax({
                type: "POST", // 使用get方法访问后台
                dataType: "json", // 返回json格式的数据
                "headers": {
                    "Content-Type": "application/json",
                    "Cache-Control": "no-cache",
                },
                url: "/api/yyghAdapter/getOrderDetail", // 要访问的后台地址
                data: JSON.stringify(params),
                success: function (data) {
                    if (data.code == "SUCCESS") {
                        if (data && data.data) {
                            /**获取预约信息*/

                            StoreCache.setCache("YYGH_YYDETAILINFO", data.data);
                            /**预约单信息赋值*/
                            data = page_yyDetailWithoutPay.getOrderInfo(data.data);
                            $("body").find(".orderInfo").each(function () {
                                if ($(this).attr("name") == "orderStatus") {
                                    $(this).text(page_yyDetailWithoutPay.getStatus(data.orderStatus));
                                } else {
                                    $(this).text(data[$(this).attr("name")]);
                                }
                            });



                        }
                    } else {
                        $.QuickAlert.alertFail({
                            content: data.message
                        });
                    }
                }
            });
        }
        /**获取并转换预约信息 */
        function getStatus(orderStatus) {
            if (orderStatus == "1") {
                orderStatus = "已预约";
            } else if (orderStatus == "2") {
                orderStatus = "已支付";
            } else if (orderStatus == "3") {
                orderStatus = "已退号";
            } else if (orderStatus == "4") {
                orderStatus = "已取号";
            } else if (orderStatus == "5") {
                orderStatus = "待退费";
            }
            return orderStatus;
        }
        /**获取并转换预约信息 */
        function getOrderInfo(data) {
            $('body').data('orderDetail', data);

            //去掉地图初始化
            //  page_yyDetailWithoutPay.initMapHandler(data);
            var orderStatus = data["orderStatus"];
            var btn;
            if (orderStatus == "1") {
                btn = $($("#cgBtn").html().replace("#orderId#", data["orderId"]));
                data["orderStatus"] = "预约成功！请按时就诊！";
                data["orderInfo"] = "请在" + data["scheduleDate"] + "按时到医院取号就诊";
            } else if (orderStatus == "2") {
                btn = $($("#qxBtn").html());

                data["orderStatus"] = "已退号";
                data["orderInfo"] = "您的预约单已取消。";


            } else if (orderStatus == "3") {
                if (data["orderType"] == "2" || data["isEvaluate"] == "0") {
                    btn = $($("#qxBtn").html());
                } else {
                    btn = $($("#jzBtn").html());
                }
                data["orderStatus"] = "已就诊！";

                if (data["isEvaluate"] == "0") {

                    data["orderStatus"] = "已评价！";
                }
                //data["orderInfo"] = "请及时就诊";
            } else if (orderStatus == "4") {
                btn = $($("#qxBtn").html());
                data["orderStatus"] = "其他";

            } else if (orderStatus == "5") {
                btn = $($("#qxBtn").html());
                data["orderStatus"] = "其他";

            } else if (orderStatus == "6") {
                btn = $($("#qxBtn").html());
                data["orderStatus"] = "其他";

            }
            /**添加按钮*/
            $(".last-btn-box").append(btn);
            if (orderStatus == "1") {
                /*$("#topay").data("payInfo",data);
                $("#topay").click(function(){
                    $('.pay-list-box').show();
                });*/
                $(".qxyy").attr("onclick", "qxyy(" + JSON.stringify(data) + ")")
            }
            $(".reservationAgain").on('click', page_yyDetailWithoutPay.zcyy);
            $(".jzpj").on('click', page_yyDetailWithoutPay.ljpj);

            data["jzsj"] = data["scheduleDate"] + " " + page_yyDetailWithoutPay.getWeek(data["scheduleDate"]) +
                " " + data["startTime"] + "-" + data["endTime"];
            var value = data["visitCost"];
            if (StringUtils.isEmpty(value)) {
                value = "0";
            }
            data["lxdh"] = ""; //" 如需帮助，请拨打客服电话：" + value;
            data["mzType"] = page_yyDetailWithoutPay.getRegType(data["regType"]) + value + "元";
            data["qxsj"] = page_yyDetailWithoutPay.getQxsj(data["scheduleDate"]);
            var patientCardId = data["patientCardId"];
            data["kh"] = patientCardId;
            data["patientCardId"] = patientCardId.substr(0, 3) + "******" + patientCardId.substr(patientCardId.length -
                4, patientCardId.length);
            var patientPhone = data["patientPhone"];
            data["patientPhone"] = patientPhone.substr(0, 3) + "******" + patientPhone.substr(patientPhone.length -
                4, patientPhone.length);
            return data;
        }
        /**根据日期获取week*/
        function getWeek(dateString) {
            if (dateString) {
                var dateArray = dateString.split("-");
                var date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]);
                return "周" + "日一二三四五六".charAt(date.getDay());
            }
        }

        /**获取取消时间*/
        function getQxsj(qxsj) {
            if (qxsj) {
                var translateDate = "",
                    dateString = "",
                    monthString = "",
                    dayString = "";
                translateDate = qxsj.replace("-", "/").replace("-", "/");
                var newDate = new Date(translateDate);
                newDate = newDate.valueOf();
                newDate = newDate - 1 * 24 * 60 * 60 * 1000;
                newDate = new Date(newDate);
                //如果月份长度少于2，则前加 0 补位
                if ((newDate.getMonth() + 1).toString().length == 1) {
                    monthString = 0 + "" + (newDate.getMonth() + 1).toString();
                } else {
                    monthString = (newDate.getMonth() + 1).toString();
                }
                //如果天数长度少于2，则前加 0 补位
                if (newDate.getDate().toString().length == 1) {
                    dayString = 0 + "" + newDate.getDate().toString();
                } else {
                    dayString = newDate.getDate().toString();
                }
                dateString = newDate.getFullYear() + "-" + monthString + "-" + dayString;
                return "取消预约截止时间为" + dateString;
            }
        }

        /**获取门诊类型*/
        function getRegType(regType) {
            var value = "";
            if (regType == "100") {
                value = "普通门诊";
            } else if (regType == "101") {
                value = "专科门诊";
            } else if (regType == "102") {
                value = "专家门诊";
            } else if (regType == "103") {
                value = "特需门诊";
            } else if (regType == "104") {
                value = "专病门诊";
            } else if (regType == "999") {
                value = "其它门诊";
            }
            return value;
        }

        /**再次预约*/
        function zcyy() {
            var orderDetail = $('body').data('orderDetail');
            $.pageSwitch.goToUrl("myOrder", "hosDetail", 'hosCode=' + orderDetail['hosCode']);
        }

        /**立即评价*/
        function ljpj() {
            // $.QuickUrlUtils.redirectJSBridge({url: "",title: "评价"});
            $.pageSwitch.goToUrl("estimate", "jzpj");
        }

        var cfg_def = {
            initData: initData,
            initMapHandler: initMapHandler,
            getStatus: getStatus,
            getOrderInfo: getOrderInfo,
            getWeek: getWeek,
            getQxsj: getQxsj,
            getRegType: getRegType,
            zcyy: zcyy,
            ljpj: ljpj,
        }

        page_yyDetailWithoutPay.init = function (cfg) {
            $.extend(page_yyDetailWithoutPay, cfg_def, cfg);
            page_yyDetailWithoutPay.initData();


        }


        return page_yyDetailWithoutPay;
    })(jQuery, {});
</script>

</html>